<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>签到</title>
    <script src="../lib/jquery-3.4.1.js"></script>
    <script src="../lib/constant.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../lib/layui/css/attendance.css" />
</head>
<body>
<div class="top flex flex-align-end flex-pack-center flex-warp">
    <div class="out-1 flex flex-align-center flex-pack-center" id="signIn">
        <div class="out-2 flex flex-align-center flex-pack-center">
            <div class="signBtn">
                <strong id="sign-txt">签到</strong>
                <span>共签到<em id="sign-count">0</em>天</span>
            </div>
        </div>
    </div>
</div>
    <div class="Calendar">
        <div id="toyear" class="flex flex-pack-center">
            <div id="idCalendarPre">&lt;</div>
            <div class="year-month">
                <span id="idCalendarYear">2021</span>年<span id="idCalendarMonth">5</span>月
            </div>
            <div id="idCalendarNext">&gt;</div>
        </div>
        <table border="1px" cellpadding="0" cellspacing="0">
            <thead>
            <tr class="tou">
                <td>日</td>
                <td>一</td>
                <td>二</td>
                <td>三</td>
                <td>四</td>
                <td>五</td>
                <td>六</td>
            </tr>
            </thead>
            <tbody id="idCalendar">
            </tbody>
        </table>
    </div>
</body>
<script type="text/javascript" src="../lib/layui/attendance.js"></script>

<script language="JavaScript">
    var isSign = false;
    var count = 0;
    var myday = new Array(); //已签到的数组
    			// myday[0] = "1528646400"
    			// myday[1] = "1"
    //			myday[2] = "1525708800"

    $(function () {
        $.ajax({
            type: 'get',
            url: RequestURL + '/sign/signInfo',
            success: function (result) {
                if (result.code == 200){
                    if (result.data.signed == 1){
                        isSign = true
                        count = result.data.count
                        $$("sign-count").innerHTML = parseInt(count);
                        $$("sign-txt").innerHTML = '已签到';
                    }
                }else if (result.code == 400){
                    alert("还没签到过哦，快点签到吧!")
                }
            }
        });
    });


    var cale = new Calendar("idCalendar", {
        qdDay: myday,
        onToday: function(o) {
            o.className = "onToday";
        },
        onSignIn: function (){
            $$("sign-txt").innerHTML = '已签到';

        },
        onFinish: function() {
            $$("sign-count").innerHTML = myday.length //已签到次数
            $$("idCalendarYear").innerHTML = this.Year;
            $$("idCalendarMonth").innerHTML = this.Month; //表头年份

        }
    });
    $$("idCalendarPre").onclick = function() {
        cale.PreMonth();
    }
    $$("idCalendarNext").onclick = function() {
        cale.NextMonth();
    }
    //添加今天签到
    $$("signIn").onclick = function() {
        if(isSign == false) {
            var res = cale.SignIn();
            if(res == '1') {
                $.ajax({
                    type: 'get',
                    url: RequestURL + '/sign/signin',
                    success: function (result) {
                        if (result.code==200){
                                $$("sign-txt").innerHTML = '已签到';
                                alert(result.msg)
                                count = result.data.count;
                                $$("sign-count").innerHTML = parseInt(count);
                                isSign = true;
                        }else if (result.code == 201){
                            alert(result.msg)
                        }
                    }
                });
            } else if (res == '2'){
                $$("sign-txt").innerHTML = '已签到';
                alert('今天已经签到了')
            }
        } else {
            alert('今天已经签到了')
        }

    }
</script>
</html>